﻿<Window x:Class="SimpleDashboardPropertyGrid"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" MinWidth="400" MinHeight="200" Width="450" Height="250" 
        xmlns:local="clr-namespace:Vivei.Tools.Modules.Provisionnement" 
        xmlns:system="clr-namespace:System;assembly=mscorlib" 
        xml:lang="fr-FR"
    Title="PropertyGrid" SizeToContent="WidthAndHeight" ShowInTaskbar="False" WindowStyle="ToolWindow"  >
    
    <Window.Resources>
       
        <DataTemplate x:Key="DefaultCellTemplate">
            <TextBlock Text="{Binding Value}" />
        </DataTemplate>

        <DataTemplate x:Key="ObjectCellEditingTemplate">
            <Button Content="Cliquer Pour Editer" Command="{Binding EditCommand}" Background="White"  />
        </DataTemplate>
        
        <DataTemplate x:Key="BrushCellTemplate">
            <Rectangle Fill="{Binding Value}" />
        </DataTemplate>

        <DataTemplate x:Key="StringCellEditingTemplate">
            <TextBox Text="{Binding Path=Value, Mode=TwoWay}" />
        </DataTemplate>

        <DataTemplate x:Key="NumericCellEditingTemplate">
            <TextBox Text="{Binding Path=Value, Mode=TwoWay}" />
        </DataTemplate>

        <DataTemplate x:Key="EnumCellEditingTemplate">
            <ComboBox  SelectedItem="{Binding Path=Value, Mode=TwoWay}" ItemsSource="{Binding PossibleValues}" />
        </DataTemplate>

        <DataTemplate x:Key="DateCellEditingTemplate">
            <TextBox Text="{Binding Path=Value, Mode=TwoWay}" />
        </DataTemplate>

        <DataTemplate x:Key="BooleanCellEditingTemplate">
            <ComboBox  SelectedItem="{Binding Path=Value, Mode=TwoWay}" ItemsSource="{Binding PossibleValues}" />
        </DataTemplate>

        <DataTemplate x:Key="BrushCellEditingTemplate">
            <ComboBox  SelectedItem="{Binding Path=Value, Mode=TwoWay}" ItemsSource="{Binding PossibleValues}" >
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Rectangle Width="20" Height="20" Margin="2" Fill="{Binding}" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
                    <ComboBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <UniformGrid />
                    </ItemsPanelTemplate>
                </ComboBox.ItemsPanel>
            </ComboBox>
        </DataTemplate>
        <DataTemplate x:Key="FontFamilyCellEditingTemplate">
            <ComboBox  SelectedItem="{Binding Path=Value, Mode=TwoWay}" ItemsSource="{Binding PossibleValues}" />
        </DataTemplate>

        <DataTemplate x:Key="FontWeightCellEditingTemplate">
            <ComboBox  SelectedItem="{Binding Path=Value, Mode=TwoWay}" ItemsSource="{Binding PossibleValues}" />
        </DataTemplate>

        <DataTemplate x:Key="FontStyleCellEditingTemplate">
            <ComboBox  SelectedItem="{Binding Path=Value, Mode=TwoWay}" ItemsSource="{Binding PossibleValues}" />
        </DataTemplate>

        <DataTemplate x:Key="ThicknessCellEditingTemplate">
            <TextBox Text="{Binding Path=Value, Mode=TwoWay}" />
        </DataTemplate>

        <DataTemplate x:Key="CornerRadiusCellEditingTemplate">
            <TextBox Text="{Binding Path=Value, Mode=TwoWay}" />
        </DataTemplate>
    </Window.Resources>
    <Grid Margin="5">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"  MinWidth="100" />
            <ColumnDefinition Width="5" />
            <ColumnDefinition />            
        </Grid.ColumnDefinitions>

        <TreeView Name="PropertiesTreeView">
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Children}">
                    <TextBlock Text="{Binding Caption}" />
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
            <!--<TreeView.ItemContainerStyle>
                <Style TargetType="TreeViewItem">
                    <Setter Property="ContextMenu">
                        <Setter.Value>
                            <ContextMenu>
                                <MenuItem Header="kkkk" />
                            </ContextMenu>
                        </Setter.Value>
                    </Setter>
                </Style>
            </TreeView.ItemContainerStyle>-->
        </TreeView>
        <GridSplitter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="1" />
        <DataGrid DataContext="{Binding ElementName=PropertiesTreeView, Path=SelectedItem}" ItemsSource="{Binding Properties}" MaxWidth="450" MaxHeight="500" Name="PropertiesDataGrid" AutoGenerateColumns="False" Grid.Column="2" ColumnWidth="*" >
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Name}" IsReadOnly="True"  />
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplateSelector>
                        <local:PropertyGridCellTemplateSelector />
                    </DataGridTemplateColumn.CellTemplateSelector>
                    <DataGridTemplateColumn.CellEditingTemplateSelector>
                        <local:PropertyGridCellEditingTemplateSelector />
                    </DataGridTemplateColumn.CellEditingTemplateSelector>
                </DataGridTemplateColumn>               
                                                 
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>
